package com.qj.yantaishan.controller;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qj.yantaishan.common.annotation.Log;
import com.qj.yantaishan.common.enums.BusinessType;
import com.qj.yantaishan.domain.ProductPropertyValue;
import com.qj.yantaishan.service.IProductPropertyValueService;
import com.qj.yantaishan.common.core.controller.BaseController;
import com.qj.yantaishan.common.core.domain.AjaxResult;
import com.qj.yantaishan.common.utils.poi.ExcelUtil;
import com.qj.yantaishan.common.core.page.TableDataInfo;

/**
 * 商品属性值Controller
 * 
 * @author qihe
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/yantaishan/ProductPropertyValue")
public class ProductPropertyValueController extends BaseController
{
    private String prefix = "yantaishan/ProductPropertyValue";

    @Autowired
    private IProductPropertyValueService productPropertyValueService;

    @RequiresPermissions("yantaishan:value:view")
    @GetMapping()
    public String value()
    {
        return prefix + "/value";
    }

    /**
     * 查询商品属性值列表
     */
    @RequiresPermissions("yantaishan:value:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProductPropertyValue productPropertyValue)
    {
        startPage();
        List<ProductPropertyValue> list = productPropertyValueService.selectProductPropertyValueList(productPropertyValue);
        return getDataTable(list);
    }

    /**
     * 导出商品属性值列表
     */
    @RequiresPermissions("yantaishan:value:export")
    @Log(title = "商品属性值", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProductPropertyValue productPropertyValue)
    {
        List<ProductPropertyValue> list = productPropertyValueService.selectProductPropertyValueList(productPropertyValue);
        ExcelUtil<ProductPropertyValue> util = new ExcelUtil<ProductPropertyValue>(ProductPropertyValue.class);
        return util.exportExcel(list, "商品属性值数据");
    }

    /**
     * 新增商品属性值
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商品属性值
     */
    @RequiresPermissions("yantaishan:value:add")
    @Log(title = "商品属性值", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProductPropertyValue productPropertyValue)
    {
        return toAjax(productPropertyValueService.insertProductPropertyValue(productPropertyValue));
    }

    /**
     * 修改商品属性值
     */
    @RequiresPermissions("yantaishan:value:edit")
    @GetMapping("/edit/{vid}")
    public String edit(@PathVariable("vid") Integer vid, ModelMap mmap)
    {
        ProductPropertyValue productPropertyValue = productPropertyValueService.selectProductPropertyValueByVid(vid);
        mmap.put("productPropertyValue", productPropertyValue);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品属性值
     */
    @RequiresPermissions("yantaishan:value:edit")
    @Log(title = "商品属性值", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProductPropertyValue productPropertyValue)
    {
        return toAjax(productPropertyValueService.updateProductPropertyValue(productPropertyValue));
    }

    /**
     * 删除商品属性值
     */
    @RequiresPermissions("yantaishan:value:remove")
    @Log(title = "商品属性值", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(productPropertyValueService.deleteProductPropertyValueByVids(ids));
    }
}
